home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / program / ixemlsrc.lha / ixemul / library / createport.c < prev    next >
C/C++ Source or Header  |  1995-12-23  |  3KB  |  111 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  $Id: createport.c,v 1.2 1994/06/19 15:09:29 rluebbert Exp $
  20.  *
  21.  *  $Log: createport.c,v $
  22.  *  Revision 1.2  1994/06/19  15:09:29  rluebbert
  23.  *  *** empty log message ***
  24.  *
  25.  */
  26.  
  27. #define KERNEL
  28. #include "ixemul.h"
  29. #include "kprintf.h"
  30.  
  31. #include <string.h>
  32.  
  33. #include <exec/ports.h>
  34. #include <exec/interrupts.h>
  35.  
  36. struct MsgPort *
  37. CreatePort(const char *name, int pri)
  38. {
  39.   int sigBit;
  40.   struct MsgPort *port;
  41.   
  42.   if ((sigBit = AllocSignal(-1)) == -1) return 0;
  43.   
  44.   port = (struct MsgPort *) kmalloc (sizeof (struct MsgPort));
  45.   if (! port)
  46.     {
  47.       FreeSignal (sigBit);
  48.       errno = ENOMEM;
  49.       KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  50.       return 0;
  51.     }
  52.     
  53.   memset(port, 0, sizeof (struct MsgPort));
  54.   
  55.   port->mp_Node.ln_Name = (char *) name;
  56.   port->mp_Node.ln_Pri = pri;
  57.   port->mp_Node.ln_Type = NT_MSGPORT;
  58.   
  59.   port->mp_Flags = PA_SIGNAL;
  60.   port->mp_SigBit = sigBit;
  61.   port->mp_SigTask = FindTask (0);
  62.   
  63.   if (name)
  64.     AddPort (port);
  65.   else
  66.     NewList (&(port->mp_MsgList));  
  67.   return port;
  68. }
  69.  
  70. struct MsgPort *
  71. CreateInterruptPort (const char *name, int pri, void (*code)(), void *data)
  72. {
  73.   struct MsgPort *port;
  74.   struct Interrupt *interrupt;
  75.   if ((port = (struct MsgPort *) kmalloc (sizeof (struct MsgPort))))
  76.     {
  77.       if ((interrupt = (struct Interrupt *) kmalloc (sizeof (struct Interrupt))))
  78.         {
  79.       memset(interrupt, 0, sizeof (struct Interrupt));
  80.  
  81.           interrupt->is_Node.ln_Type = NT_INTERRUPT;
  82.       /* as a convenience, if data is 0, set it to the port itself */
  83.           interrupt->is_Data = data ? data : port; /*rwl*/
  84.           interrupt->is_Code = code;
  85.           
  86.           bzero (port, sizeof (struct MsgPort));
  87.  
  88.       port->mp_Node.ln_Name = (char *) name;
  89.       port->mp_Node.ln_Pri = pri;
  90.       port->mp_Node.ln_Type = NT_MSGPORT;
  91.           
  92.       port->mp_Flags = PA_SOFTINT;
  93.       port->mp_SoftInt = interrupt;
  94.  
  95.  
  96.       if (name)
  97.         AddPort (port);
  98.       else
  99.         NewList (&(port->mp_MsgList));
  100.  
  101.       return port;
  102.     }
  103.       
  104.       kfree (port);
  105.     }
  106.  
  107.   errno = ENOMEM;
  108.   KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  109.   return 0;
  110. }
  111.